Understanding Computer Programming

Osher Lifelong Learning Institute
University of Illinois, Urbana-Champaign

Scott Badman, Instructor


Topic: IF statements - another basic element of programming

February 4, 2016


IF comparison(s) THEN

    One or more lines of code that is done if the comparison is true.

ELSE (optional)

    One or more lines of code that is done if the comparison is false.

END IF

In any case, the program continues here after the END IF.


IF -- THEN -- ELSE(optional) -- ENDIF is one of the fundamental elements of programming.

When the IF comparison is true, the program does the instructions between the THEN and the ELSE and continues after the END IF.

When the IF comparison is false, the program does the instructions between the ELSE and the END IF and continues after the END IF.

ELSE is optional. When the ELSE is missing and the IF condition is false, the program just continues after the END IF, doing nothing.

IF -- THEN -- ELSE(optional) -- ENDIF is included in almost every programming language, possibly with slightly different syntax.

IF's and WHILE's may be nested inside each other without restriction. Programmers normally indent nested IF's and WHILE's.

IF's and WHILE loops are very similar, except the code inside the IF is executed once at the most, and possibly not at all.




Understanding Computer Programming

Osher Lifelong Learning Institute
University of Illinois, Urbana-Champaign

Scott Badman, Instructor